home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 235 / Issue 235 - September 2007 - DPCS0907DVD.ISO / Microsoft / Expression Blend / Blend.en.msi / Sparkle.PBook.ImageCollection.cs.en < prev    next >
Encoding:
Text File  |  2007-03-19  |  3.7 KB  |  78 lines

  1.  ■using System.Collections.ObjectModel;
  2. using System;
  3. using System.IO;
  4. using System.Windows;
  5. namespace PhotoBook
  6. {
  7.     /// <summary>
  8.     /// Data Model that holds the images of the pages.
  9.     /// </summary>
  10.     public class ImageCollection
  11.     {
  12.         private ObservableCollection<string> images = new ObservableCollection<string>();
  13.         private string location;
  14.         public ImageCollection()
  15.         {
  16.         }
  17.         #region Public Attributes
  18.         public ObservableCollection<string> Images
  19.         {
  20.             get { return this.images; }
  21.         }
  22.         public string Location
  23.         {
  24.             get { return this.location; }
  25.             set
  26.             {
  27.                 this.location = value;
  28.                 this.Reload();
  29.             }
  30.         }
  31.         public string FirstImage
  32.         {
  33.             get
  34.             {
  35.                 if (this.Images.Count != 0)
  36.                 {
  37.                     return this.Images[0];
  38.                 }
  39.                 else
  40.                 {
  41.                     return "";
  42.                 }
  43.             }
  44.         }
  45.         #endregion
  46.         private void Reload()
  47.         {
  48.             this.images.Clear();
  49.             if (Directory.Exists(this.location))
  50.             {
  51.                 DirectoryInfo dir = new DirectoryInfo(this.location);
  52.                 foreach (FileInfo file in dir.GetFiles("*.*", SearchOption.AllDirectories))
  53.                 {
  54.                     if (this.IsImage(file))
  55.                         this.images.Add(file.FullName);
  56.                 }
  57.             }
  58.         }
  59.         private bool IsImage(FileInfo file)
  60.         {
  61.             String ext = file.Extension.ToLower();
  62.             if (ext == ".jpg" || ext == ".gif" || ext == ".png")
  63.                 return true;
  64.             return false;
  65.         }
  66.     }
  67. }